*******************************************
*** Replication for "Silencing Their Critics: How Government Restrictions Against Civil Society Affect International Naming and Shaming"
*** Authors: Hannah Smidt, Dominic Perera, Neil Mitchell, Kristin Bakke
*** Date: 27.6.2019

*** Models in Main Manuscript
log using Output_Main, replace text

set more off
version 13.0
clear

cd " " // Change to the directory where you saved the data and the VarLabels.do

use "dataForAnalysis_v3.dta", clear


** Trend in restrictions over time
destring YEAR, replace
drop if YEAR<1994
preserve
collapse (mean) RESTRICT_COUNTdom RESTRICT_COUNTdom2, by(YEAR)
tab RESTRICT_COUNTdom2 if YEAR==1994
tab RESTRICT_COUNTdom2 if YEAR==1998
tab RESTRICT_COUNTdom2 if YEAR==2016
#delimit ;
twoway line RESTRICT_COUNTdom2 YEAR, scheme(s1mono)
xscale(range(1994 2016))  xlabel(1994(2)2016) 
yscale(range(0 2)) ylabel(0 (0.5) 2)
color("gray") lwidth(1.2)
ytitle("Mean number of restriction types", size(large)) 
xtitle("Time in years", size(large)) ;
#delimit cr
graph export ".\Figures\Manuscript_Figure1.png", replace
restore


** Data management
drop if YEAR>2007 | YEAR<1994
xtset cowcode YEAR

** Labels
do "VarLabels.do"


**************************************************************
* Model 1: Negative binomial with robust standard errors
**************************************************************
set seed 1234
#delimit ;
nbreg urgentActions c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1, vce(cluster cowcode) ;
#delimit cr

estat ic
mat es_ic = r(S)
mat list es_ic
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Manuscript_Table1.doc", replace ///
 ctitle("Model 1") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')

margins, at(RESTRICT_COUNTdomlag1 = (0 6)) contrast(atcontrast(r)) //   9.051235   2.416684      4.314622    13.78785
margins, at(RESTRICT_COUNTdomlag1 = (6 10)) contrast(atcontrast(r)) // -7.129509   2.383362     -11.80081   -2.458206

margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) )
marginsplot, recast(line) recastci(rarea)  ///
yscale(range(0 16))  ylabel(0(2)16) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of UAs", size(large)) ///
title("Model 1", size(large)) ///
scheme(s1mono)


**************************************************************
* Model 2: Negative binomial with robust se standard errors and covariates
**************************************************************
set seed 1234
#delimit ;
nbreg urgentActions c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(cluster cowcode);
#delimit cr
capture drop sample
gen sample = 1 if e(sample)==1

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Manuscript_Table1.doc", append ///
 ctitle("Model 2") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')

margins, at(RESTRICT_COUNTdomlag1 = (0 7)) contrast(atcontrast(r)) //  4.391923   1.191021      2.432868    6.350978
margins, at(RESTRICT_COUNTdomlag1 = (7 10)) contrast(atcontrast(r)) //  -1.974416   1.095854     -3.776937   -.1718962

margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
display _b[8._at] - _b[11._at]		
display _b[8._at] - _b[1._at]		
test _b[8._at] = _b[11._at] 
test _b[8._at] = _b[1._at] 
marginsplot, recast(line) recastci(rarea)  ///
yscale(range(0 10))  ylabel(0(2)10) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of UAs", size(large)) ///
title("Model 2", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure3a.png", replace


**************************************************************
** Summary stats, and other statistics
**************************************************************

** Appendix 1: Correlation matrix between restriction types
mkcorr SOME_BANNED VISIT_RESTRICT TRAVEL_RESTRICT FUNDING_DOM ///
  FUNDING_INT REGISTRATION_PROBLEMS CENSOR HARASS_AMOUNT_bi SURVEIL_bi  ///
  ARREST_bi KILLING_bi if sample==1, log(Appendix_TableS1) replace


** Appendix 2: Summary statistics table
estpost summarize urgentActions urgentActionslag1 shamingINGO shamingINGOlag1 RESTRICT_COUNTdomlag1 ///
PTS_Slag1 hrgroupslag1 hrnewslag1 protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 ///
PR_freedomHouselag1 PR_freedomHouselag1_sq gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq ///
KOFGIlag1 KOFGIlag1_sq populationlag1 fhbest fhworst deathpenalty if sample==1, detail
esttab . using ".\Tables\Appendix_TableS2.rtf", cells("mean(fmt(2)) sd min max count") title("Table 1. Summary Statistics") nonumber label replace

** How many countries have 0-5 restrictions, 6-10 restrictions
capture drop min
bysort cowcode: egen min = min(RESTRICT_COUNTdomlag1)
capture drop max
bysort cowcode: egen max = max(RESTRICT_COUNTdomlag1)
tab COUNTRY if min<=5 & max<=5 & sample==1
codebook COUNTRY if min<=5 & max<=5 & sample==1
tab COUNTRY if max>5 & max!=. & sample==1
codebook COUNTRY if max>5 & max!=.& sample==1
capture drop min max


** Loess curve plot
#delimit ;
twoway lowess urgentActions RESTRICT_COUNTdomlag1 if sample==1 ,
color("gray") lwidth(1.2) ||
scatter urgentActions RESTRICT_COUNTdomlag1 if sample==1 & urgentActions<=60,
scheme(s1mono) msize(0.75) mcolor(gs0)
xscale(range(0 10))  xlabel(0(1)10) 
yscale(range(0 60)) ylabel(0 (20) 60)
xtitle("Number of restriction types", size(large)) 
ytitle("Number of UAs", size(large)) legend(off);
#delimit cr
graph export ".\Figures\Manuscript_Figure2.png", replace


** Appendix 3: Figure S2 (Egypt plots)
#delimit ;
twoway line RESTRICT_COUNTdomlag1 YEAR if YEAR>=1998 & YEAR<=2007 & COUNTRY=="Egypt" ,
color("red") lwidth(1.2)
scheme(s1mono) msize(0.75) mcolor(gs0)
yscale(range(0 10)) ylabel(0 (1) 10)
xscale(range(1998 2007)) xlabel(1998 (1) 2007)
xtitle("Time in years", size(large)) 
ytitle("Number of restriction types", size(large)) legend(off);
#delimit cr
graph export ".\Figures\Appendix_FigureS3b_1.png", replace

#delimit ;
twoway line urgentActions YEAR if YEAR>=1998 & YEAR<=2007 & COUNTRY=="Egypt" ,
color("blue") lwidth(1.2)
scheme(s1mono) msize(0.75) mcolor(gs0)
xscale(range(1998 2007)) xlabel(1998 (1) 2007)
yscale(range(0 40)) ylabel(0 (4) 40)
xtitle("Time in years", size(large)) 
ytitle("Number of UAs", size(large)) legend(off);
#delimit cr
graph export ".\Figures\Appendix_FigureS3b_2.png", replace



*************************************************************
* Model 3: Zero inflated negative binomial 
*************************************************************
set seed 1234
#delimit ;
zinb urgentActions c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, 
inflate(fhbest fhworst UCDP_armedConflictlag1 deathpenalty urgentActionslag1) 
vce(cluster cowcode); // vuong ;
#delimit cr
predict yhat, n

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Manuscript_Table1.doc", append ///
ctitle("Model 3") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')

margins, at(RESTRICT_COUNTdomlag1 = (0 7)) contrast(atcontrast(r)) //    2.80838   .7413316      1.588998    4.027762
margins, at(RESTRICT_COUNTdomlag1 = (7 10)) contrast(atcontrast(r)) // -1.497769   .6840491      -2.62293   -.3726088

margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
display _b[8._at] - _b[11._at]		
display _b[8._at] - _b[1._at]		
test _b[8._at] = _b[11._at] 
marginsplot, recast(line) recastci(rarea)  ///
yscale(range(0 10)) ylabel(0(2)10) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of UAs", size(large)) ///
title("Model 3", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure3b.png", replace

** Plot: Predicted vs actual UAs
capture drop diag*
gen diag = 0 in 1
replace diag = 30 in 2
gen diag2 = diag
#delimit ;
twoway scatter yhat urgentActions if urgentActions<=20 || 
scatter yhat urgentActions if COUNTRY=="Egypt", mcolor("blue") ||
line diag diag2,
yscale(range(0 30)) ylabel(0(5)30)
xscale(range(0 30)) xlabel(0(5)30)
lwidth(1) lcolor(gs02)
xtitle("Observed number of UAs", size(large)) 
ytitle("Predicted number of UAs", size(large)) 
legend(off)
scheme(s1mono) ;
#delimit cr
graph export ".\Figures\Appendix_FigureS3a.png", replace




******************************************************************************
** Model 4: GMM: Instrumental Variable Poisson with bootstrapped standard errors; only two instrumented variables
******************************************************************************

** Some tests: 
*Poisson with bootstrapped SE (to compare to GMM-estimated model parameter estimates)
xtset, clear
capture drop vhat*
#delimit ;
poisson urgentActions c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr
* Endogeneity
#delimit ;
reg RESTRICT_COUNTdomlag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3, vce(boot, reps(20) cl(cowcode)) ;
predict vhat1, resid ;
reg RESTRICT_COUNTdomlag1_sq gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 RESTRICT_COUNTdomlag2_sq RESTRICT_COUNTdomlag3_sq, vce(boot, reps(20) cl(cowcode)) ;
predict vhat2, resid ;
poisson urgentActions RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 vhat1 vhat2, vce(boot, reps(20) cl(cowcode)) ;
test vhat1 vhat2 ;
#delimit cr
* Test of instruments
* Restrictions
#delimit ;
reg RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(50) cl(cowcode));
#delimit cr
test RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
* Restriction sq.
#delimit ;
reg RESTRICT_COUNTdomlag1_sq RESTRICT_COUNTdomlag2_sq RESTRICT_COUNTdomlag3_sq
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(50) cl(cowcode));
#delimit cr
test RESTRICT_COUNTdomlag2_sq RESTRICT_COUNTdomlag3_sq


** GMM (with 2 EEVs)
xtset, clear
set seed 2
#delimit ;
ivpoisson gmm urgentActions
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1
( RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq = 
	RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
	RESTRICT_COUNTdomlag2_sq)
	, twostep vce(boot, reps(50) cl(cowcode) seed(1)) ;
#delimit cr
estat overid

mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".\Tables\Manuscript_Table1.doc", append ///
 ctitle("Model 4") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')

set level 95
margins, at(RESTRICT_COUNTdomlag1 = (0 6) RESTRICT_COUNTdomlag1_sq = (0 36)) contrast(atcontrast(r)) //      4.869633   1.798345      1.344942    8.394325
margins, at(RESTRICT_COUNTdomlag1 = (6 10) RESTRICT_COUNTdomlag1_sq = (36 100)) contrast(atcontrast(r)) //   -3.151206   1.681949     -6.447765    .1453536
set level 90
margins, at(RESTRICT_COUNTdomlag1 = (6 10) RESTRICT_COUNTdomlag1_sq = (36 100)) contrast(atcontrast(r)) //    -3.151206   1.681949     -5.917765   -.3846459
set level 95
margins, at(RESTRICT_COUNTdomlag1 = (7 10) RESTRICT_COUNTdomlag1_sq = (49 100)) contrast(atcontrast(r)) //   -3.151206   1.681949     -6.447765    .1453536
margins, at(RESTRICT_COUNTdomlag1 = 0 RESTRICT_COUNTdomlag1_sq = 0 ) ///
			 at(RESTRICT_COUNTdomlag1 = 1 RESTRICT_COUNTdomlag1_sq = 1 ) ///
			 at(RESTRICT_COUNTdomlag1 = 2 RESTRICT_COUNTdomlag1_sq = 4 ) ///
			 at(RESTRICT_COUNTdomlag1 = 3 RESTRICT_COUNTdomlag1_sq = 9 ) ///
			 at(RESTRICT_COUNTdomlag1 = 4 RESTRICT_COUNTdomlag1_sq = 16 ) ///
			 at(RESTRICT_COUNTdomlag1 = 5 RESTRICT_COUNTdomlag1_sq = 25 ) ///
			 at(RESTRICT_COUNTdomlag1 = 6 RESTRICT_COUNTdomlag1_sq = 36 ) ///
			 at(RESTRICT_COUNTdomlag1 = 7 RESTRICT_COUNTdomlag1_sq = 49 ) ///
			 at(RESTRICT_COUNTdomlag1 = 8 RESTRICT_COUNTdomlag1_sq = 64 ) ///
			 at(RESTRICT_COUNTdomlag1 = 9 RESTRICT_COUNTdomlag1_sq = 81 ) ///
			 at(RESTRICT_COUNTdomlag1 = 10 RESTRICT_COUNTdomlag1_sq = 100 ) post
display _b[7._at] - _b[1._at]	 // 4.8109192
test _b[7._at] = _b[1._at]		 
display _b[11._at]	- _b[7._at]	 // -3.1527847
test _b[7._at] = _b[11._at]	

marginsplot, recast(line) recastci(rarea)  ///
yscale(range(0 10)) ylabel(0(2)10) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "10") ///
xtitle("Count of restriction types",size(large)) ///
ytitle("Predicted number of UAs",size(large)) ///
title("Model 4",size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure3c.png", replace




******************************************************************************
** Model 4: GMM: Instrumental Variable Poisson with bootstrapped standard errors; only all endogenous variables instrumented
******************************************************************************

** Test of endogeneity
capture drop vhat3
capture drop vhat4
capture drop vhat5
capture drop vhat6
capture drop vhat7
capture drop vhat8
capture drop vhat9
#delimit ;
reg PTS_Slag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PTS_Slag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat3, resid ;
reg hrgroupslag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 hrgroupslag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat4, resid ;
reg hrnewslag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 hrnewslag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat5, resid ;
reg protest_ClarkRegan_loglag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 protest_ClarkRegan_loglag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat6, resid ;
reg UCDP_armedConflictlag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 UCDP_armedConflictlag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat7, resid ;
reg PR_freedomHouselag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PR_freedomHouselag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat8, resid ;
reg PR_freedomHouselag1_sq gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PR_freedomHouselag2_sq, vce(boot, reps(20) cl(cowcode)) ;
predict vhat9, resid ;
poisson urgentActions gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 
RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag2_sq
PTS_Slag2 hrgroupslag2 hrnewslag2 
protest_ClarkRegan_loglag2 UCDP_armedConflictlag2 
PR_freedomHouselag2 PR_freedomHouselag2_sq 
vhat*, vce(boot, reps(20) cl(cowcode)) ;
test vhat3 vhat4 vhat5 vhat6 vhat7 vhat8 vhat9 ;
test vhat3 ; 
test vhat4 ; // hrgroupslag1 n.s.
test vhat5 ; // hrnewslag1 n.s.
test vhat6 ;
test vhat7 ; // UCDP_armedConflict n.s.
test vhat8 ; 
test vhat9 ; // PR_freedomHouselag1_sq n.s.
#delimit cr

** Test endogeneity with transformed DV (OLS)
capture gen urgentActions_log = log(urgentActions+1)
* H0: Potential EVVs may be treated as exogenous
tsset cowcode YEAR
#delimit ;
ivreg2 urgentActions_log
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1
(RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq =
RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3 RESTRICT_COUNTdomlag2_sq
PTS_Slag2 hrgroupslag2 hrnewslag2 
protest_ClarkRegan_loglag2 UCDP_armedConflictlag2 
PR_freedomHouselag2 PR_freedomHouselag2_sq), 
gmm cluster(cowcode)
endogtest(RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq 
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq) ;
#delimit cr
* The endogeneity test can reject its null that the potential IIV may be treated as exogenous; they ARE ENDOGENOUS
* Hansen's J: We can NOT reject the null hypothesis that instruments are uncorrelated with the errors; instruments ARE JOINTLY VALID
* Kleibergen-Paap / underidentification: We can reject the null hypothesis of underidentification; Instruments ARE RELEVANT



** Test of instruments
tsset, clear
* PTS_Slag1
#delimit ;
reg PTS_Slag1 RESTRICT_COUNTdomlag1_sq RESTRICT_COUNTdomlag1
PTS_Slag2 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr
* protest_ClarkRegan_loglag1
#delimit ;
reg protest_ClarkRegan_loglag1 RESTRICT_COUNTdomlag1_sq RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag2
protest_ClarkRegan_loglag2 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr
* PR_freedomHouselag1 
#delimit ;
reg PR_freedomHouselag1  RESTRICT_COUNTdomlag1_sq RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag1
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1
PR_freedomHouselag2 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr
* PR_freedomHouselag1_sq
#delimit ;
reg PR_freedomHouselag1_sq  RESTRICT_COUNTdomlag1_sq RESTRICT_COUNTdomlag1
PTS_Slag1 hrgroupslag1 hrnewslag1
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1
PR_freedomHouselag1 PR_freedomHouselag2_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr


** GMM
xtset, clear
#delimit ;
ivpoisson gmm urgentActions
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq 
hrgroupslag1 hrnewslag1 
populationlag1  UCDP_armedConflictlag1 
(RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq 
PTS_Slag1 PR_freedomHouselag1 PR_freedomHouselag1_sq
protest_ClarkRegan_loglag1 = 
	RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
	RESTRICT_COUNTdomlag2_sq
	PTS_Slag2 
	PR_freedomHouselag2
	PR_freedomHouselag2_sq 
	protest_ClarkRegan_loglag2 )
, twostep vce(boot, reps(50) cl(cowcode) seed(1)) ;
#delimit cr
estat overid 

mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".\Tables\Manuscript_Table1.doc", append ///
 ctitle("Model 6") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')

margins, at(RESTRICT_COUNTdomlag1 = (0 6) RESTRICT_COUNTdomlag1_sq = (0 36)) contrast(atcontrast(r)) //     5.126616   2.135579      .9409588    9.312273
margins, at(RESTRICT_COUNTdomlag1 = (6 10) RESTRICT_COUNTdomlag1_sq = (36 100)) contrast(atcontrast(r))  //   -3.525839   1.718657     -6.894346   -.1573325
 
margins, at(RESTRICT_COUNTdomlag1 = 0 RESTRICT_COUNTdomlag1_sq = 0 ) ///
		 at(RESTRICT_COUNTdomlag1 = 1 RESTRICT_COUNTdomlag1_sq = 1 ) ///
		 at(RESTRICT_COUNTdomlag1 = 2 RESTRICT_COUNTdomlag1_sq = 4 ) ///
		 at(RESTRICT_COUNTdomlag1 = 3 RESTRICT_COUNTdomlag1_sq = 9 ) ///
		 at(RESTRICT_COUNTdomlag1 = 4 RESTRICT_COUNTdomlag1_sq = 16 ) ///
		 at(RESTRICT_COUNTdomlag1 = 5 RESTRICT_COUNTdomlag1_sq = 25 ) ///
		 at(RESTRICT_COUNTdomlag1 = 6 RESTRICT_COUNTdomlag1_sq = 36 ) ///
		 at(RESTRICT_COUNTdomlag1 = 7 RESTRICT_COUNTdomlag1_sq = 49 ) ///
		 at(RESTRICT_COUNTdomlag1 = 8 RESTRICT_COUNTdomlag1_sq = 64 ) ///
		 at(RESTRICT_COUNTdomlag1 = 9 RESTRICT_COUNTdomlag1_sq = 81 ) ///
		 at(RESTRICT_COUNTdomlag1 = 10 RESTRICT_COUNTdomlag1_sq = 100 ) level(95) post
display _b[7._at] - _b[11._at]		 // 3.5237687
display _b[7._at] - _b[1._at]		 // 4.8123955
test _b[7._at] = _b[11._at]	
test _b[7._at] = _b[1._at]		
marginsplot, recast(line) recastci(rarea) level(95) ///
yscale(range(0 10))  ylabel(0(2)10) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "10") ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of UAs", size(large)) ///
title("Model 5",size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure3d.png", replace



****************************************************
****** Mechanism implications, Figures 4 and 5 *****
****************************************************

********************
*** Number of CSOs
********************

** Table S9a

** Model 1: Negative binomial with robust standard errors
#delimit ;
nbreg hrgroups c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1, vce(cluster cowcode) ;
#delimit cr

estat ic
mat es_ic = r(S)
mat list es_ic
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Appendix_TableS9a.doc", replace ///
 ctitle("Model 1") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')



* Model 2: Negative binomial with robust se
#delimit ;
nbreg hrgroups c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(cluster cowcode);
#delimit cr

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Appendix_TableS9a.doc", append ///
 ctitle("Model 2") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')


** Main Manuscript: Figure S4
margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
marginsplot, recast(line) recastci(rarea)  ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of human rights groups", size(large)) ///
title("Number of CSOs", size(large)) subtitle("-- Negative Binomial --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure4.png", replace


** Model 3
 
* Test: Poisson with bootstrapped SE (to compare to GMM-estimated model parameter estimates)
xtset, clear
capture drop vhat*
#delimit ;
poisson hrgroups c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(boot, reps(20) cl(cowcode));
#delimit cr

* Endogeneity
capture drop vhat*
#delimit ;
reg RESTRICT_COUNTdomlag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3, vce(boot, reps(20) cl(cowcode)) ;
predict vhat1, resid ;
reg RESTRICT_COUNTdomlag1_sq gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 RESTRICT_COUNTdomlag2_sq RESTRICT_COUNTdomlag3_sq, vce(boot, reps(20) cl(cowcode)) ;
predict vhat2, resid ;
poisson hrgroups RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq
PTS_Slag1 hrgroupslag1 hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 vhat1 vhat2, vce(boot, reps(20) cl(cowcode)) ;
test vhat1 vhat2 ;
test vhat1 ;
test vhat2 ;
#delimit cr

** GMM (with 2 EEVs)
xtset, clear
#delimit ;
ivpoisson gmm hrgroups
PTS_Slag1  hrnewslag1 
protest_ClarkRegan_loglag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1
( RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq = 
	RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
	RESTRICT_COUNTdomlag2_sq)
	, twostep vce(boot, reps(50) cl(cowcode) seed(1)) ;
#delimit cr
estat overid

mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".\Tables\Appendix_TableS9a.doc", append ///
 ctitle("Model 3") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')

margins, at(RESTRICT_COUNTdomlag1 = 0 RESTRICT_COUNTdomlag1_sq = 0 ) ///
			 at(RESTRICT_COUNTdomlag1 = 1 RESTRICT_COUNTdomlag1_sq = 1 ) ///
			 at(RESTRICT_COUNTdomlag1 = 2 RESTRICT_COUNTdomlag1_sq = 4 ) ///
			 at(RESTRICT_COUNTdomlag1 = 3 RESTRICT_COUNTdomlag1_sq = 9 ) ///
			 at(RESTRICT_COUNTdomlag1 = 4 RESTRICT_COUNTdomlag1_sq = 16 ) ///
			 at(RESTRICT_COUNTdomlag1 = 5 RESTRICT_COUNTdomlag1_sq = 25 ) ///
			 at(RESTRICT_COUNTdomlag1 = 6 RESTRICT_COUNTdomlag1_sq = 36 ) ///
			 at(RESTRICT_COUNTdomlag1 = 7 RESTRICT_COUNTdomlag1_sq = 49 ) ///
			 at(RESTRICT_COUNTdomlag1 = 8 RESTRICT_COUNTdomlag1_sq = 64 ) ///
			 at(RESTRICT_COUNTdomlag1 = 9 RESTRICT_COUNTdomlag1_sq = 81 ) ///
			 at(RESTRICT_COUNTdomlag1 = 10 RESTRICT_COUNTdomlag1_sq = 100 ) post

marginsplot, recast(line) recastci(rarea)  ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "10") ///
xtitle("Count of restriction types",size(large)) ///
ytitle("Predicted number of human rights groups",size(large)) ///
title("Number of CSOs", size(large)) subtitle("-- Poisson with GMM --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Appendix_FigureS9a_1.png", replace



** Model 4: GMM with all endogenous explanatory variables

* Test of endogeneity
capture drop vhat3
capture drop vhat4
capture drop vhat5
capture drop vhat6
capture drop vhat7
capture drop vhat8
capture drop vhat9
#delimit ;
reg PTS_Slag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PTS_Slag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat3, resid ;
reg hrnewslag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 hrnewslag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat5, resid ;
reg protest_ClarkRegan_loglag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 protest_ClarkRegan_loglag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat6, resid ;
reg UCDP_armedConflictlag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 UCDP_armedConflictlag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat7, resid ;
reg PR_freedomHouselag1 gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PR_freedomHouselag2, vce(boot, reps(20) cl(cowcode)) ;
predict vhat8, resid ;
reg PR_freedomHouselag1_sq gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 PR_freedomHouselag2_sq, vce(boot, reps(20) cl(cowcode)) ;
predict vhat9, resid ;
poisson hrgroups gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1 
RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag2_sq
PTS_Slag2 hrnewslag2 
protest_ClarkRegan_loglag2 UCDP_armedConflictlag2 
PR_freedomHouselag2 PR_freedomHouselag2_sq 
vhat*, vce(boot, reps(20) cl(cowcode)) ;
test vhat1 vhat2 vhat3 vhat5 vhat6 vhat7 vhat8 vhat9 ;
test vhat1 ; // Restrictions
test vhat2 ; // Restrictions_sq
test vhat3 ; // PTS SIGNIFICANT
test vhat5 ; // hrnewslag1 SIGNIFICANT
test vhat6 ; // protest_ClarkRegan_loglag2 SIGNIFICANT
test vhat7 ; // UCDP_armedConflict n.s.
test vhat8 ; // PR_freedomHouselag1 n.s.
test vhat9 ; // PR_freedomHouselag1_sq n.s.
#delimit cr


xtset, clear
#delimit ;
ivpoisson gmm hrgroupslag1
PR_freedomHouselag1 PR_freedomHouselag1_sq
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq 
populationlag1  UCDP_armedConflictlag1 
(RESTRICT_COUNTdomlag1 RESTRICT_COUNTdomlag1_sq 
PTS_Slag1  hrnewslag1 
protest_ClarkRegan_loglag1 = 
	RESTRICT_COUNTdomlag2 RESTRICT_COUNTdomlag3
	RESTRICT_COUNTdomlag2_sq
	PTS_Slag2 PTS_Slag3 
	hrnewslag2
	protest_ClarkRegan_loglag2)
, twostep vce(boot, reps(50) cl(cowcode) seed(2)) ;
#delimit cr
estat overid 

mat es_ic = r(J) 
matrix list es_ic
local J: display %4.1f es_ic[1,1]
outreg2 using ".\Tables\Appendix_TableS9a.doc", append ///
 ctitle("Model 4") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Hansen's J, `J')

margins, at(RESTRICT_COUNTdomlag1 = (0 4) RESTRICT_COUNTdomlag1_sq = (0 16)) contrast(atcontrast(r)) //    5.640214   2.477502      .7843994    10.49603
margins, at(RESTRICT_COUNTdomlag1 = (4 10) RESTRICT_COUNTdomlag1_sq = (16 100)) contrast(atcontrast(r))  // -3.854784   1.831316     -7.444098   -.2654707
 
margins, at(RESTRICT_COUNTdomlag1 = 0 RESTRICT_COUNTdomlag1_sq = 0 ) ///
		 at(RESTRICT_COUNTdomlag1 = 1 RESTRICT_COUNTdomlag1_sq = 1 ) ///
		 at(RESTRICT_COUNTdomlag1 = 2 RESTRICT_COUNTdomlag1_sq = 4 ) ///
		 at(RESTRICT_COUNTdomlag1 = 3 RESTRICT_COUNTdomlag1_sq = 9 ) ///
		 at(RESTRICT_COUNTdomlag1 = 4 RESTRICT_COUNTdomlag1_sq = 16 ) ///
		 at(RESTRICT_COUNTdomlag1 = 5 RESTRICT_COUNTdomlag1_sq = 25 ) ///
		 at(RESTRICT_COUNTdomlag1 = 6 RESTRICT_COUNTdomlag1_sq = 36 ) ///
		 at(RESTRICT_COUNTdomlag1 = 7 RESTRICT_COUNTdomlag1_sq = 49 ) ///
		 at(RESTRICT_COUNTdomlag1 = 8 RESTRICT_COUNTdomlag1_sq = 64 ) ///
		 at(RESTRICT_COUNTdomlag1 = 9 RESTRICT_COUNTdomlag1_sq = 81 ) ///
		 at(RESTRICT_COUNTdomlag1 = 10 RESTRICT_COUNTdomlag1_sq = 100 ) level(95) post
marginsplot, recast(line) recastci(rarea) level(95) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xlabel(1 "0" 2 "1" 3 "2" 4 "3" 5 "4" 6 "5" 7 "6" 8 "7" 9 "8" 10 "9" 11 "10") ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of human rights groups", size(large)) ///
title("Number of CSOs", size(large)) subtitle("-- Poisson with GMM (all EEVs) --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Appendix_FigureS9a_2.png", replace


******************
** Protest *******
******************

** Table S9b

* Model 1: Negative binomial with robust standard errors
#delimit ;
nbreg protest_ClarkRegan c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1, vce(cluster cowcode) ;
#delimit cr

estat ic
mat es_ic = r(S)
mat list es_ic
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Appendix_TableS9b.doc", replace ///
 ctitle("Model 1") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')



* Model 2: Negative binomial with robust se
#delimit ;
nbreg protest_ClarkRegan c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrnewslag1  UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(cluster cowcode);
#delimit cr

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using  ".\Tables\Appendix_TableS9b.doc", append ///
 ctitle("Model 2") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')

margins, at(RESTRICT_COUNTdomlag1 = (0 3)) contrast(atcontrast(r)) //     .3340292   .4830276     -.6126876    1.280746
margins, at(RESTRICT_COUNTdomlag1 = (3 10)) contrast(atcontrast(r)) //   -.8653467   .8708952      -2.57227    .8415765

margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
marginsplot, recast(line) recastci(rarea)  ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of protest events", size(large)) ///
title("Nunber of Protest Events", size(large)) ///
subtitle("-- Negative Binomial --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Manuscript_Figure5.png", replace


* Model 3: Zero inflated negative binomial 
set seed 1
#delimit ;
zinb protest_ClarkRegan c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrnewslag1 UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, 
inflate(fhbest fhworst gdp_pc_constantUS2010lag1 )
vce(cluster cowcode);
#delimit cr


estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using  ".\Tables\Appendix_TableS9b.doc", append ///
 ctitle("Model 3") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')

margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
marginsplot, recast(line) recastci(rarea)  ///
yscale(range(0 4))  ylabel(0(1)4) ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of protest events", size(large)) ///
title("Number of Protest Events ", size(large)) ///
subtitle("-- Zero-infl. Negative Binomial --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Appendix_FigureS9b_1.png", replace



* Model 4: Linear regression
#delimit ;
reg protest_ClarkRegan_log c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1, vce(cluster cowcode);
#delimit cr

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Appendix_TableS9b.doc", append ///
 ctitle("Model 4") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')


* Model 5: Linear regression, full
#delimit ;
reg protest_ClarkRegan_log c.RESTRICT_COUNTdomlag1##c.RESTRICT_COUNTdomlag1
PTS_Slag1 hrnewslag1  UCDP_armedConflictlag1 
PR_freedomHouselag1 PR_freedomHouselag1_sq 
gdp_pc_constantUS2010lag1 gdp_pc_constantUS2010lag1_sq 
KOFGIlag1 KOFGIlag1_sq populationlag1, vce(cluster cowcode);
#delimit cr

estat ic
mat es_ic = r(S)
local AIC: display %4.1f es_ic[1,5]
local BIC: display %4.1f es_ic[1,6]
local LL: display %4.1f es_ic[1,3]
outreg2 using ".\Tables\Appendix_TableS9b.doc", append ///
 ctitle("Model 5") label  eqdrop(lnalpha) dec(3) ///
alpha(0.001, 0.01, 0.05, 0.1) symbol(***,**, *, +) ///
addtext(Log-Likelihood, `LL', BIC, `BIC', AIC, `AIC')


margins, at(RESTRICT_COUNTdomlag1 = (0(1)10) ) post
marginsplot, recast(line) recastci(rarea)  ///
plotopt(color(gs0) lwidth(1) ) ///
ciopt(color(gs6) fintensity(10) lcolor(gs16) ) ///
xtitle("Count of restriction types", size(large)) ///
ytitle("Predicted number of protest events", size(large)) ///
title("Nunber of Protest Events", size(large)) ///
subtitle("-- OLS with covariates --", size(large)) ///
scheme(s1mono)
graph export ".\Figures\Appendix_FigureS9b_2.png", replace


log close
